package com.library.control.find;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
import org.springframework.web.servlet.mvc.AbstractFormController;

import com.library.model.dto.register.FindPassDTO;
import com.library.model.service.PassFindService;

public class PassFindController extends AbstractFormController {

	private PassFindService passfindservice;
	
	public void setPassfindservice(PassFindService passfindservice) {
		this.passfindservice = passfindservice;
	}
	
	@Override
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		String member_id=request.getParameter("member_id");
		String name=request.getParameter("name");
		String jumin=request.getParameter("jumin1")+"-"+request.getParameter("jumin2");
		FindPassDTO dto=new FindPassDTO(member_id,name,jumin);
		return dto;
	}

	@Override
	protected ModelAndView processFormSubmission(HttpServletRequest arg0,
			HttpServletResponse arg1, Object arg2, BindException arg3)
			throws Exception {
		ModelAndView mav=new ModelAndView();
		String pass=passfindservice.findPass((FindPassDTO)arg2);
		mav.addObject("pass", pass);
		mav.setViewName("findpassok");
		return mav;
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest arg0,
			HttpServletResponse arg1, BindException arg2) throws Exception {
		return new ModelAndView("passfindform");
	}

}
